package cn.com.checne;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

/**
 * Created with IntelliJ IDEA.
 * User: zy
 * To change this template use File | Settings | File Templates.
 */
public class Test {

    public static void main(String[] args) {
        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        threadMXBean.setThreadContentionMonitoringEnabled(true);
        long[] tid = threadMXBean.getAllThreadIds();
        ThreadInfo threadInfo[] = threadMXBean.getThreadInfo(tid, Integer.MAX_VALUE);
        long threadArrays[][] = new long[threadInfo.length][2];
        for (int i = 0; i < threadInfo.length; i++) {
            long threadId = threadInfo[i].getThreadId();
            long cpuTime = threadMXBean.getThreadCpuTime(threadInfo[i].getThreadId() / (1000 * 1000 * 1000));
            threadArrays[i][0] = threadId;
            threadArrays[i][1] = cpuTime;
        }
    }
}
